<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('配送方式列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <div class="select-list">
                    <ul>
                        <li>
                            配送方式名称：<input type="text" name="wayName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="back:logisticsWay:add">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('back:logisticsWay:edit')}]];
    var removeFlag = [[${@permission.hasPermi('back:logisticsWay:remove')}]];

    var showStatusDict = [[${@dict.getType('custom_normal_disable')}]];
    var isEnableDict = [[${@dict.getType('is_enable')}]];

    var prefix = ctx + "back/logisticsWay";

    /* 改变状态 */
    function changeStatus(id, isEnable) {
        isEnable = Math.abs(parseInt(isEnable) - 1);
        $.operate.post(prefix + "/edit", {id: id, isEnable: isEnable}, function () {
            $.table.refresh();
        })
    }

    $(function () {
        var options = {
            url: prefix + "/searchList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "配送方式",
            sortName: "orderNum asc,createTime",
            sortOrder: "desc",
            clickToSelect:true,
            columns: [
                {
                    field: 'id',
                    title: '配送方式ID'
                },
                {
                    field: 'wayName',
                    title: '配送方式名称'
                },
                {
                    field: 'templateName',
                    title: '配送模板名称',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    field: 'isDefault',
                    title: '是否默认',
                    sortable:true,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(isEnableDict, value);
                    }
                },
                {
                    field: 'isEnable',
                    title: '状态',
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(showStatusDict, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'orderNum',
                    title: '排序',
                    sortable:true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable:true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit">编辑</i></a> ');
                        if ("0" == row.isEnable) {
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="#" onclick="changeStatus(\'' + row.id + '\',\'' + row.isEnable + '\')"><i class="fa fa-check">启用</i></a>');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove">删除</i></a> ');
                        }
                        if ("1" == row.isEnable) {
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="changeStatus(\'' + row.id + '\',\'' + row.isEnable + '\')"><i class="fa fa-ban">禁用</i></a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>